package com.three.server.oss;



import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.smartcar.common.constants.OssConstant;

import java.io.File;

/**
 * @author 赵暹宇
 */
public class UploadFile {

    /**
     * oss上传
     * @param file
     * @return
     */
    private static final String endpoint = OssConstant.ENDPOINT;
    private static final String accessKeyId = OssConstant.ACCESS_KEY_ID;
    private static final String accessKeySecret = OssConstant.ACCESS_KEY_SECRET;


    public static  String upload(File file){
        try {
            //创建Oss实例
            OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
            ossClient.putObject(OssConstant.BUCKET_NAME, file.getName(), file);
            System.out.println("上传成功");
            ossClient.shutdown();
            return OssConstant.UPLOAD_PATH + file.getName();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
